home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group96b.txt
/
000053_icon-group-sender _Wed Nov 6 20:56:32 1996.msg
< prev
next >
Wrap
Internet Message Format
|
1997-01-02
|
4KB
Received: by cheltenham.cs.arizona.edu; Thu, 7 Nov 1996 09:34:00 MST
Date: Wed, 6 Nov 1996 20:56:32 -0600
Message-Id: <199611070256.UAA20251@ns1.computek.net>
Mime-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: gep2@computek.net
Subject: sets and structures
To: icon-group@cs.arizona.edu
X-Mailer: SPRY Mail Version: 04.00.06.17
Errors-To: icon-group-errors@cs.arizona.edu
>i'm reading ``An Overview of the Icon Programming Language; Version 8''
(Griswold). the section on sets says: ``insert(S, x) has no effect if x
is already in S''.
>this appears to work for atomic types eg,
procedure main()
local l, s
s := set()
while(l := read()) do
insert(s, l)
every l := !s do
write(l)
end
>however, if if i try to insert a structure then it never fails,
It's not going to "fail"... storing an item into a table (or set) which is
identical to an item already in the table (or set) simply means that the one
already there which matches is effectively overwritten (in the case of a table;
in the case of a set where there is no "data value" associated with the key, it
doesn't matter which one you want to consider is discarded, since they're both
identical). A set can basically be thought of just like a table, except without
a specific data value corresponding to the key.
> record rec(a,b)
procedure main()
local l, s
s := set()
while(l := read()) do {
a := l[1]
b := l[2:0]
insert(s, rec(a,b))
}
every l := !s do
write(l.a, " ", l.b)
end
>results in output like:
>; structest
foo
bar
bar
spam
b ar
s pam
f oo
b ar
;
>as you would expect for a list rather than a set. so, what's the answer
if you want to form a set of non-atomic types?
You sort of need to understand SNOBOL4 where a lot of this stuff originated. In
SNOBOL4, two variables which both contain the same string value each point to
EXACTLY the same single copy of that string. In such a case, it's very easy to
detect identity: if the pointers to the data descriptors that describe the two
strings are the same, then the two strings are identical. Otherwise, they are
not. So even two strings of thousands of characters can be "compared" for
equality by simply comparing two one-word values!
Likewise, if you set (again, in SNOBOL4, but ICON is basically the same)
a = table()
b = a
then 'a' and 'b' point to the SAME table. Changes to table 'a' will be
reflected in table 'b'; " ident(a,b) " would succeed. If on the other hand you
have:
a = table()
b = table()
then 'a' and 'b' are distinct and independent tables, whether they happen to
contain identical contents or not. " ident(a,b) " would fail, even immediately
after the two assignment statements above (where both 'a' and 'b' are identical,
empty tables).
>do i have to do it by hand?
Yes, pretty much. Although of course ICON and SNOBOL4 can make this relatively
easy for you, in most cases. Clearly, if the items you want to compare are two
separately allocated arrays, (or worse, tables... which might have been created
in different chronology!) each one containing thousands of items of a variety of
data types (patterns? code?) then clearly determining (efficiently!) if they
are really functionally identical or not (based on their present content!) could
be rather challenging, indeed!
Gordon Peterson
http://www.computek.net/public/gep2/